import { DemonstrationWriter } from "./DemonstrationWriter";
import { GrpcProxy } from "./proxy/GrpcProxy";


/**
 * @en Registration method for the main process of Extension
 * @zh 为扩展的主进程的注册方法
 */
export const methods: { [key: string]: (...any: any) => any } = {

    openDemonstrationWriter: (name: string, path: string) => {
        DemonstrationWriter.open(name, path);
    },

    writeDemonstrationBuffer: (name: string, buffer: Buffer) => {
        DemonstrationWriter.writeBuffer(name, buffer);
    },

    closeDemonstrationWriter: (name: string) => {
        DemonstrationWriter.close(name);
    },

    seekDemonstrationWriter: (name: string, offset: number) => {
        DemonstrationWriter.seek(name, offset);
    },

    beforeQuit: (name: string, offset: number) => {
        GrpcProxy.getInstance().stop();
    }
    ,
    startProxy:(name: string, offset: number) => {
        GrpcProxy.getInstance().start();
    },

    stopProxy:(name: string, offset: number) => {
        GrpcProxy.getInstance().stop();
    }
};

/**
 * @en Hooks triggered after extension loading is complete
 * @zh 扩展加载完成后触发的钩子
 */
export function load() {
    GrpcProxy.getInstance().start();
}

/**
 * @en Hooks triggered after extension uninstallation is complete
 * @zh 扩展卸载完成后触发的钩子
 */
export function unload() {
    GrpcProxy.getInstance().stop();
}
